<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        
        #app {
            width: 500px;
            margin: 20px auto;
            background: skyblue;
        }
        
        .list_one {
            height: 80px;
            line-height: 80px;
            background: palevioletred;
            margin-top: 10px;
            display: flex;
            justify-content: space-between;
            padding: 0 30px;
            box-sizing: border-box;
            cursor: pointer;
        }
        
        #app .active {
            background: green;
        }
    </style>
</head>

<body>
    <div id="app">
        <h1>列表</h1>
        <div class="list">
            <div :class="['list_one',item.active?'active':'']" @click="change(item)" v-for="(item,index) in services" :key="index">
                <span>{{item.name}}</span> <span>${{item.price}}</span>
            </div>
        </div>
        <hr>
        <div class="list_one" style="background: none;">
            <span>total</span> <span>￥{{total}}</span>
        </div>
    </div>
    <script src="./vue.js"></script>
    <script>
        new Vue({
            el: "#app",
            data() {
                return {
                    services: [{
                        name: 'Web Development',
                        price: 300,
                        active: true
                    }, {
                        name: 'Design',
                        price: 400,
                        active: false
                    }, {
                        name: 'Integration',
                        price: 250,
                        active: true
                    }, {
                        name: 'Training',
                        price: 220,
                        active: false
                    }]
                }
            },
            methods: {
                change(item) {
                    item.active = !item.active;
                }
            },
            computed: {
                total() { //求和
                    var count = 0;
                    this.services.forEach((ele, index) => {
                        if (ele.active) {
                            count += ele.price
                        }
                    })
                    return count
                }
            }
        })
    </script>
</body>

</html>